<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
  * {
    margin: 0;
    padding: 0;
  }
  canvas {
    border: 1px solid #000;
  }
  </style>
</head>
<body>
  <canvas id="myCanvas" style="width: 50vw; height: 50vh;"></canvas>
  <script>
  const canvas = document.getElementById('myCanvas');
  var ctx = canvas.getContext('2d');
  ctx.fillStyle = 'red';
  ctx.font="50px Verdana";
  ctx.fillText(1, 100, 100);
  let dis = 10;
//   function animation() {
//      requestAnimationFrame(function() {
//       //  console.log('----');
//       ctx.clearRect(0,0,300,150);
//       ctx.fillText(++dis,100,100);
//       animation();
//      })
//    } 
//    animation();
setInterval(() => {
        ctx.clearRect(0,0,300,150);
        ctx.fillText(--dis,100,100);
        },1000);
  </script>
</body>
</html>